package com.javadaemon.rpgengine.model;


/*
 Copyright (c) 2011, Morten Andersen
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 * The name of the author may not be used to endorse or promote products
 derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL MORTEN ANDERSEN BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * The class encapsulates the information which relates to a specific tile.
 * 
 * @author Somnium
 * 
 */
public class Tile {

    // It can sometimes be an advantage to let a tile know its own x/y
    // coordinates as well as
    // the tilemap it belongs to - although this is redundant (as this mapping
    // between coordinates
    // and tile instances already exists in the TileMap class), it can simplify
    // logic, f.x. by allowing
    // a tile to be passed as an argument to f.x. movement methods, instead of
    // coordinates.
    // For simplicity, this is not the case in this example.
    private TILE_TYPE type; // The tile type of the tile (the base terrain of the tile)
    private TileObject tileObject;
    private Actor actor; // A possible actor that lives on the tile

    public Tile(TILE_TYPE type) {
	this.type = type;
    }
    
    /**
     * This is called from the Actor instance, in finishmove(). It's used for effects like tile animation, and effects like teleportation.
     * The standard tile doesn't need any of these, so we'll just leave it empty and let the inherited classes use it.
     * @param actor
     * 			The Actor that is approaching
     */
    public void onApproach(Actor actor, TileMap map) {
	
    }

    public TILE_TYPE getType() {
	return type;
    }

    public void setType(TILE_TYPE type) {
	this.type = type;
    }

    public void setActor(Actor actor) {
	this.actor = actor;
    }

    public Actor getActor() {
	return actor;
    }

    public boolean isBlocking() {
	if (tileObject != null) {
	    if (tileObject.isBlocking()) {
		return true;
	    }
	}
	if (type.isBlocking() || actor != null) {
		return true;
	}
	else {
	    return false;
	}
    }
    
    public TileObject getObject() {
	return tileObject;
    }
    
    public void setObject(TileObject object) {
	this.tileObject = object;
    }
}
